package cn.ruihusoft.ql.service.impl;

import cn.ruihusoft.ql.client.UserClient;
import cn.ruihusoft.ql.core.QlSdkInit;
import cn.ruihusoft.ql.pojo.Response;
import cn.ruihusoft.ql.pojo.user.UserLoginRequest;
import cn.ruihusoft.ql.pojo.user.UserTokenResponse;
import cn.ruihusoft.ql.service.UserService;
import com.dtflys.forest.http.ForestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserClient userClient;

    @Override
    public UserTokenResponse token(String clientId, String clientSecret) {
        Response<UserTokenResponse> response = userClient.token(QlSdkInit.getClientId(), QlSdkInit.getClientSecret());
        return response.getData();
    }

    @Override
    public void login(String username, String password) {
        UserLoginRequest request = new UserLoginRequest();
        request.setUsername(username);
        request.setPassword(password);

        ForestResponse<String> response = userClient.login(request);

        log.info("登录接口返回结果:{}", response.getResult());
    }
}
